﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using MikroObject;

namespace Aktarim
{
    public partial class frmAyarlar : XtraForm
    {
        public frmAyarlar()
        {
            InitializeComponent();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            for (int i = 1; i < vGridControl1.Rows.Count; i++)
            {
                if (vGridControl1.Rows[i].Properties.Value != null)
                    Config.GetConfig.Add((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName), vGridControl1.Rows[i].Properties.Value.ToString());
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void frmAyarlar_Load(object sender, EventArgs e)
        {
            for (int i = 1; i < vGridControl1.Rows.Count; i++)
            {
                if (!string.IsNullOrEmpty(vGridControl1.Rows[i].Properties.FieldName))
                {
                    switch (vGridControl1.Rows[i].Properties.UnboundType)
                    {
                        case DevExpress.Data.UnboundColumnType.Boolean:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToBoolean(Config.GetConfig.GetValue((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName)));
                            break;
                        case DevExpress.Data.UnboundColumnType.DateTime:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToDateTime(Config.GetConfig.GetValue((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName)));
                            break;
                        case DevExpress.Data.UnboundColumnType.Decimal:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToDecimal(Config.GetConfig.GetValue((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName)));
                            break;
                        case DevExpress.Data.UnboundColumnType.Integer:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToInt32(Config.GetConfig.GetValue((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName)));
                            break;
                        case DevExpress.Data.UnboundColumnType.String:
                            vGridControl1.Rows[i].Properties.Value = Convert.ToString(Config.GetConfig.GetValue((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName)));
                            break;
                        default:
                            vGridControl1.Rows[i].Properties.Value = Config.GetConfig.GetValue((CParams)Enum.Parse(typeof(CParams), vGridControl1.Rows[i].Properties.FieldName));
                            break;
                    }
                }
            }
        }
    }
}
